package com.yangchao.exception;

import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.Map;

@ControllerAdvice
public class GlobalExceptionHandler {

    // @ResponseBody
    // @ExceptionHandler(ArithmeticException.class)
    // public Map<String, Object> error(ArithmeticException exception) {
    //     System.out.println("全局算数异常");
    //     return new HashMap<>() {{
    //         put("异常", "算数异常");
    //     }};
    // }


    @ResponseBody
    @ExceptionHandler(ArithmeticException.class)
    public Map error(ArithmeticException exception) {
        System.out.println("全局算数异常");
        return new HashMap<>() {{
            put("异常", "算数异常");
        }};
    }
}
